#include<bits/stdc++.h>
using namespace std;

typedef pair<int, pair<int, string>> Tuple;
vector<Tuple> table;

int main(){
    int n;
    cin>>n;
    int id, old;
    string name;
    for(int i=0; i<n; ++i){
        cin>> id >> name >> old;
        table.push_back({ old, {id, name}});
    }
    sort(table.begin(), table.end());

    for(int i=0; i<3; ++i){
        cout<<table[i].second.first <<' '<< table[i].second.second << ' ' << table[i].first<<endl;
    }

    return 0;
}